from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from dragger.drag.models import DraggableArea, DraggableItem

def index(request):
  return render_to_response('index.html', {})

def view(request, da_id):
  da = get_object_or_404(DraggableArea, id=da_id)
  di = da.item
  return render_to_response('dragger.html', {"da_height": da.height, "da_width": da.width, "da_image": da.image, "da_id": da.id, "di":di, "di_x": di.x, "di_y": di.y }, context_instance=RequestContext(request))

@login_required
def edit_di(request, da_id, di_x, di_y):
  da = get_object_or_404(DraggableArea, id=da_id)
  di = da.item
  di.x = di_x
  di.y = di_y
  di.save()
  return HttpResponse('')

